package com.xxxx.car.appointment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.xxxx.car.appointment.vo.ServiceItemAuditInfo;
import com.xxxx.car.appointment.vo.ServiceItemVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xxxx.car.common.annotation.Log;
import com.xxxx.car.common.core.controller.BaseController;
import com.xxxx.car.common.core.domain.AjaxResult;
import com.xxxx.car.common.enums.BusinessType;
import com.xxxx.car.appointment.domain.ServiceItem;
import com.xxxx.car.appointment.service.IServiceItemService;
import com.xxxx.car.common.utils.poi.ExcelUtil;
import com.xxxx.car.common.core.page.TableDataInfo;

/**
 * 汽车服务项Controller
 * 
 * @author Huang
 * @date 2024-08-26
 */
@RestController
@RequestMapping("/appointment/serviceItem")
public class ServiceItemController extends BaseController
{
    @Autowired
    private IServiceItemService serviceItemService;

    /**
     * 查询汽车服务项列表
     */
    @PreAuthorize("@ss.hasPermi('appointment:serviceItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServiceItem serviceItem)
    {
        startPage();
        List<ServiceItem> list = serviceItemService.selectServiceItemList(serviceItem);
        return getDataTable(list);
    }

    /**
     * 导出汽车服务项列表
     */
    @PreAuthorize("@ss.hasPermi('appointment:serviceItem:export')")
    @Log(title = "汽车服务项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceItem serviceItem)
    {
        List<ServiceItem> list = serviceItemService.selectServiceItemList(serviceItem);
        ExcelUtil<ServiceItem> util = new ExcelUtil<ServiceItem>(ServiceItem.class);
        util.exportExcel(response, list, "汽车服务项数据");
    }

    /**
     * 获取汽车服务项详细信息
     */
    @PreAuthorize("@ss.hasPermi('appointment:serviceItem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(serviceItemService.selectServiceItemById(id));
    }

    /**
     * 获取服务项审核信息
     */
    @PreAuthorize("@ss.hasPermi('appointment:serviceItem:auditInfo')")
    @GetMapping(value = "/getAuditInfo/{id}")
    public AjaxResult getAuditInfo(@PathVariable("id") Long id)
    {
        ServiceItemAuditInfo info = serviceItemService.selectAuditInfoById(id);
        return success(info);
    }

    /**
     * 新增汽车服务项
     */
    @PreAuthorize("@ss.hasPermi('appointment:serviceItem:add')")
    @Log(title = "汽车服务项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody ServiceItemVo serviceItemVo)
    {
        return toAjax(serviceItemService.insertServiceItem(serviceItemVo));
    }

    /**
     * 修改汽车服务项
     */
    @PreAuthorize("@ss.hasPermi('appointment:serviceItem:edit')")
    @Log(title = "汽车服务项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody ServiceItemVo serviceItemVo)
    {
        return toAjax(serviceItemService.updateServiceItem(serviceItemVo));
    }

    /**
     * 删除汽车服务项
     */
    @PreAuthorize("@ss.hasPermi('appointment:serviceItem:remove')")
    @Log(title = "汽车服务项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(serviceItemService.deleteServiceItemByIds(ids));
    }

    /**
     * 上下架汽车服务项
     */
    @Log(title = "修改上架状态", businessType = BusinessType.UPDATE)
    @PutMapping("/saleStatus/{id}")
    public AjaxResult updateSaleStatus(@PathVariable Long id)
    {
        return toAjax(serviceItemService.updateSaleStatus(id));
    }
}
